// LaserCodeUserdefValueDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Lightning.h"
#include "LaserCodeUserdefValueDlg.h"
#include "afxdialogex.h"


// CLaserCodeUserdefValueDlg dialog

IMPLEMENT_DYNAMIC(CLaserCodeUserdefValueDlg, CDialogEx)

CLaserCodeUserdefValueDlg::CLaserCodeUserdefValueDlg(CWnd* pParent /*=NULL*/)
	: CDialogEx(CLaserCodeUserdefValueDlg::IDD, pParent)
{
	nSel = -1;
	strTemplate = _T("");
}

CLaserCodeUserdefValueDlg::~CLaserCodeUserdefValueDlg()
{
}

void CLaserCodeUserdefValueDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CLaserCodeUserdefValueDlg, CDialogEx)
	ON_BN_CLICKED(IDC_BTN_OK, &CLaserCodeUserdefValueDlg::OnBnClickedBtnOk)
	ON_BN_CLICKED(IDC_BTN_CANCLE, &CLaserCodeUserdefValueDlg::OnBnClickedBtnCancle)
END_MESSAGE_MAP()


// CLaserCodeUserdefValueDlg message handlers


void CLaserCodeUserdefValueDlg::OnBnClickedBtnOk()
{
	// TODO: Add your control notification handler code here
	CString str;
	if (nSel > -1)
	{
		if (strTemplate != _T(""))
		{
			GetDlgItemText(IDC_EDIT_USERDEF_VALUE, str);
			if (str != _T(""))
			{
				strTemplate.SetAt(nSel, str.GetAt(0));
				CDialogEx::OnOK();
			}
		}
	}
}


void CLaserCodeUserdefValueDlg::OnBnClickedBtnCancle()
{
	// TODO: Add your control notification handler code here
	CDialogEx::OnCancel();
}


BOOL CLaserCodeUserdefValueDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  Add extra initialization here
	CString str;
	if (nSel > -1)
	{
		str.Format(_T("%2d --->"), nSel);
		SetWindowText(str);
		if (strTemplate != _T(""))
		{
			str.Format(_T("%c"), strTemplate.GetAt(nSel));
			SetDlgItemText(IDC_EDIT_USERDEF_VALUE, str);
		}
	}
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


BOOL CLaserCodeUserdefValueDlg::PreTranslateMessage(MSG* pMsg)
{
	// TODO: Add your specialized code here and/or call the base class
	if (pMsg->message == WM_KEYDOWN)
	{
		if (pMsg->wParam == VK_RETURN || pMsg->wParam == VK_ESCAPE)
		{
			return TRUE;
		}
	}
	return CDialogEx::PreTranslateMessage(pMsg);
}
